package com.example.cdctestsystem.filter;


import com.example.cdctestsystem.util.PageContext;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
@WebFilter("/*")
public class PageFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        int pageNum;
        try {
            pageNum = Integer.parseInt(servletRequest.getParameter("pageNum"));
        } catch (NumberFormatException e) {
            pageNum=1;
        }
        try {
            PageContext.setPageNum(pageNum);
            filterChain.doFilter(servletRequest, servletResponse);
        } finally {
            PageContext.clear();
        }
    }
}
